import requests
from bs4 import BeautifulSoup

cookies = {
    'bid': 'bMCOc2NN9hE',
    '_pk_id.100001.4cf6': 'cc16d104b49cbbfe.1702965609.',
    '_pk_ses.100001.4cf6': '1',
    'ap_v': '0,6.0',
    '__utma': '30149280.1068612282.1702965610.1702965610.1702965610.1',
    '__utmb': '30149280.0.10.1702965610',
    '__utmc': '30149280',
    '__utmz': '30149280.1702965610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
    '__utma': '223695111.1426292687.1702965610.1702965610.1702965610.1',
    '__utmb': '223695111.0.10.1702965610',
    '__utmc': '223695111',
    '__utmz': '223695111.1702965610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
}

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    # 'Referer':'https://movie.douban.com/subject/35208463/comments',
    # 'Cookie': 'bid=bMCOc2NN9hE; _pk_id.100001.4cf6=cc16d104b49cbbfe.1702965609.; _pk_ses.100001.4cf6=1; ap_v=0,6.0; __utma=30149280.1068612282.1702965610.1702965610.1702965610.1; __utmb=30149280.0.10.1702965610; __utmc=30149280; __utmz=30149280.1702965610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=223695111.1426292687.1702965610.1702965610.1702965610.1; __utmb=223695111.0.10.1702965610; __utmc=223695111; __utmz=223695111.1702965610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'none',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
    'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}
url = 'https://movie.douban.com/subject/25662329/comments'
# response = requests.get('https://movie.douban.com/subject/35208463/comments?comment_id=4017521577', params=params, cookies=cookies, headers=headers)
page = 1
while True:
    page_url = f'{url}?start={page*20}&limit=20&status=P&sort=new_score'
    response = requests.get(page_url,  cookies=cookies, headers=headers)
    if response.status_code == 200:
        soup = BeautifulSoup(response.content, 'html.parser')
        comments = soup.find_all('p', class_='comment-content')
        file = open("666.txt", mode='a')
        for comment in comments:
            text = comment.span.text.strip()
            print(text)
            #file.write(text)
        page = page + 1
    else:
        break
